package com.sy.controller;

import com.sy.bean.GoodsWarehouse;
import com.sy.bean.SaveGoods;
import com.sy.bean.WarehouseGoods;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.service.SaveGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "新增商品")
@RequestMapping("/api/set")
public class SaveGoodsController extends BaseController {
    @Autowired
    SaveGoodsService saveGoodsService;
    @ApiOperation("新增商品")
    @PostMapping("/goods/save")
    public ResultBean save(@RequestBody SaveGoods saveGoods, BindingResult result){
        validate(result);
        return gotoResult(saveGoodsService.save(saveGoods),"新增");
    }
    @ApiOperation("商品id查询所在仓库")
    @PostMapping("/goods/warehouse")
    public ResultBean queryByGoodsId(@RequestBody Map map){
        List<GoodsWarehouse> list = saveGoodsService.queryGoodsWarehouse(map);
        return success("商品所在仓库列表",list);
    }
}
